package com.clkj.zhonghui.controller.system;

import com.clkj.zhonghui.pojo.system.Url;
import com.clkj.zhonghui.pojo.common.Result;
import com.clkj.zhonghui.pojo.common.StatusCode;
import com.clkj.zhonghui.service.system.UrlService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author：周佳润
 * @Date：2024/7/10 上午10:32
 */
@RestController
@RequestMapping(value = "/url")
@CrossOrigin
@Api(value = "/url", tags = {"中汇URL"})
public class UrlController {

    @Autowired
    private UrlService urlService;
    @ApiOperation(value = "添加地址")
    @PostMapping("/addUrl")
    public Result addAddress(Url url){
        try {
            urlService.addUrl(url);
            return new Result(true, StatusCode.OK,"添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"添加失败");
        }

    }

    @ApiOperation(value = "获取地址列表")
    @PostMapping("/listUrl")
    public Result listUrl(Integer urlId){
        try {
            List<Url> addrList  = urlService.listUrl(urlId);
            return new Result(true, StatusCode.OK,"查询成功",addrList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }

    }
    @ApiOperation(value = "更新地址")
    @PostMapping("/updateUrl")
    public Result updateUrl(@RequestBody Url url){
        try {
            urlService.updateUrl(url);
            return new Result(true, StatusCode.OK,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"修改失败");
        }

    }
    @ApiOperation(value = "删除地址")
    @PostMapping("/delUrl")
    public Result delUrl(@RequestParam("urlId") Integer urlId){
        try {
            urlService.delUrl(urlId);
            return new Result(true, StatusCode.OK,"删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"删除失败");
        }

    }

}
